package com.wc.alorithm_blue_bridge_history.fourteen.子矩阵;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.LinkedList;

/**
 * @Author congege
 * @Description
 * @Date Created in 2023/11/20-20:12
 * 子矩阵
 * https://www.dotcpp.com/oj/problem3161.html
 */
public class Main {
    public static void main(String[] args) {
        long mod = 998244353;
        Input sc = new Input();
        int n = sc.nextInt();
        int m = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int[][] map = new int[n + 5][m + 5];
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                map[i][j] = sc.nextInt();
            }
        }
        MyQueue maxQueue = new MyQueue();
        MyQueue minQueue = new MyQueue(false);

        for (int i = 1; i <= a; i++) {
            for (int j = 1; j <= b; j++) {
                maxQueue.push(map[i][j]);
                minQueue.push(map[i][j]);
            }
        }
        long ans = maxQueue.front() * minQueue.front() % mod;

        int row = 1;
        int ud = n - a + 1;
        int lr = m - b;
        for (int i = 1; i <= ud; i++) {
            if (row % 2 == 1) {
                for (int j = 1; j <= lr; j++) {
                    for (int k = a + i - 1; k >= i; k--) {
                        maxQueue.pop(map[k][j]);
                        minQueue.pop(map[k][j]);
                    }
                    for (int k = a + i - 1; k >= i; k--) {
                        maxQueue.push(map[k][j + b]);
                        minQueue.push(map[k][j + b]);
                    }
                    ans += maxQueue.front() * minQueue.front() % mod;
                    ans %= mod;
                }
                maxQueue.clear();
                minQueue.clear();
                for (int k = i + 1; k <= i + a; k++) {
                    for (int j = m; j > lr; j--) {
                        maxQueue.push(map[k][j]);
                        minQueue.push(map[k][j]);
                    }
                }
            } else {
                for (int j = m; j > b; j--) {
                    for (int k = a + i - 1; k >= i; k--) {
                        maxQueue.pop(map[k][j]);
                        minQueue.pop(map[k][j]);
                    }
                    for (int k = a + i - 1; k >= i; k--) {
                        maxQueue.push(map[k][j - b]);
                        minQueue.push(map[k][j - b]);
                    }
                    ans += maxQueue.front() * minQueue.front() % mod;
                    ans %= mod;
                }
                maxQueue.clear();
                minQueue.clear();
                for (int k = i + 1; k <= i + a; k++) {
                    for (int j = 1; j <= b; j++) {
                        maxQueue.push(map[k][j]);
                        minQueue.push(map[k][j]);
                    }
                }
            }
            ans += maxQueue.front() * minQueue.front() % mod;
            ans %= mod;
            row++;
        }

        System.out.println(ans);
    }

    static class MyQueue {
        public LinkedList<Integer> queue;
        public boolean isBig;

        public MyQueue(boolean isBig) {
            this.isBig = isBig;
            queue = new LinkedList<>();
        }

        public MyQueue() {
            this(true);
        }

        public long front() {
            return queue.get(0);
        }

        public void push(int val) {
            if (isBig) {
                while (!queue.isEmpty() && val > queue.getLast()) {
                    queue.removeLast();
                }
            } else {
                while (!queue.isEmpty() && val < queue.getLast()) {
                    queue.removeLast();
                }
            }
            queue.add(val);
        }

        public void pop(int val) {
            if (!queue.isEmpty() && val == queue.get(0)) {
                queue.remove(0);
            }
        }

        public void clear() {
            queue.clear();
        }
    }

    static class Input {
        StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

        public long nextLong() {
            try {
                in.nextToken();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return (long) in.nval;
        }

        public int nextInt() {
            try {
                in.nextToken();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return (int) in.nval;
        }
    }
}
